package cn.lbd.bilibili.controller;

import cn.lbd.bilibili.model.BulletScreenParams;
import cn.lbd.bilibili.model.MergeMapParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

@Controller
public class BiliController {
    @Autowired
    private RestTemplate restTemplate;
    private Logger logger = LoggerFactory.getLogger(getClass());

    @ResponseBody
    @RequestMapping(value = "/",method = RequestMethod.GET)
    public String toIndex() {
        return "<h1 style='color: green'>Hello Jenkins</h1>";
    }

    @ResponseBody
    @RequestMapping(value = "/dologin")
    @CrossOrigin(origins ="*")
    public Map test(/*@RequestParam String callback*/) {
        Map map = new HashMap();
        map.put("msg",200);
        /*return callback + "(" + JSON.toJSONString(map) +")";*/
        return map;
    }
    /**
     * 直播
     */
    @RequestMapping("/bili/live")
    @ResponseBody
    public void live(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询直播换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.live.bilibili.com/xlive/web-interface/v1/webMain/getList?platform=web"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("查询直播换一换接口成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 番剧杂谈
     */
    @RequestMapping("/bili/hisDramaGossip")
    @ResponseBody
    public void hisDramaGossip(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询番剧杂谈换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=1"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("番剧杂谈换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 时尚
     */
    @RequestMapping("/bili/fashion")
    @ResponseBody
    public void fashion(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询时尚换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=155"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("时尚换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 国产原创
     */
    @RequestMapping("/bili/domesticOriginal")
    @ResponseBody
    public void domesticOriginal(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询国产原创换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=168"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("国产原创换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 音乐
     */
    @RequestMapping("/bili/music")
    @ResponseBody
    public void music(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询音乐换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=3"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("音乐换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 舞蹈
     */
    @RequestMapping("/bili/dance")
    @ResponseBody
    public void dance(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询舞蹈换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=129"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("舞蹈换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 纪录片
     */
    @RequestMapping("/bili/documentary")
    @ResponseBody
    public void documentary(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询纪录片换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=177"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("纪录片换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 数码
     */
    @RequestMapping("/bili/digital")
    @ResponseBody
    public void digital(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询数码换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=188"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("数码换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 生活
     */
    @RequestMapping("/bili/toLive")
    @ResponseBody
    public void toLive(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询生活换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=160"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("生活换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 鬼畜
     */
    @RequestMapping("/bili/theDemon")
    @ResponseBody
    public void theDemon(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询鬼畜换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=119"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("鬼畜换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 知识
     */
    @RequestMapping("/bili/knowledge")
    @ResponseBody
    public void knowledge(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询知识换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=36"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("知识换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 游戏
     */
    @RequestMapping("/bili/game")
    @ResponseBody
    public void game(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询游戏换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=4"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("游戏换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 漫画
     */
    @RequestMapping("/bili/caricature")
    @ResponseBody
    public void caricature(@RequestParam String callback, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        logger.info("查询漫画换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .postForObject("https://manga.bilibili.com/twirp/comic.v1.Comic/GetRecommendComics",
                        null, String.class));
        try {
            response.getWriter().print(jsonObject);
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("漫画换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 漫画右侧排行榜中的应援(POST请求)：https://manga.bilibili.com/twirp/comic.v1.Comic/HomeFans
     */
    /*@RequestMapping("/bili/reinforce")
    @ResponseBody
    public void reinforce(@RequestParam String callback, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin","*");
        logger.info("查询漫画右侧排行榜中的应援接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .postForObject("https://manga.bilibili.com/twirp/comic.v1.Comic/HomeFans",
                        null, String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("漫画右侧排行榜中的应援接口查询成功！返回参数 = >"+jsonObject.toJSONString());
    }*/

    /**
     * 漫画右侧排行榜中的飙升(POST请求)：https://manga.bilibili.com/twirp/comic.v1.Comic/HomeHot
     */
    /*@RequestMapping("/bili/surge")
    @ResponseBody
    public void surge(@RequestParam String callback, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin","*");
        logger.info("查询漫画右侧排行榜中的飙升接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .postForObject("https://manga.bilibili.com/twirp/comic.v1.Comic/HomeHot",
                        null, String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("漫画右侧排行榜中的飙升接口查询成功！返回参数 = >"+jsonObject.toJSONString());
    }*/
    /**
     * 漫画右侧排行榜中的月票(POST请求)：https://manga.bilibili.com/twirp/comic.v1.Comic/HomeFans
     */
    /*@RequestMapping("/bili/monthlyPass")
    @ResponseBody
    public void monthlyPass(@RequestParam String callback, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin","*");
        logger.info("查询漫画右侧排行榜中的月票接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .postForObject("https://manga.bilibili.com/twirp/comic.v1.Comic/HomeFans",
                       null, String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("漫画右侧排行榜中的月票接口查询成功！返回参数 = >"+jsonObject.toJSONString());
    }*/

    /**
     * 动画
     */
    @RequestMapping("/bili/cartoon")
    @ResponseBody
    public void cartoon(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询动画换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=13"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("动画换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 资讯
     */
    @RequestMapping("/bili/consult")
    @ResponseBody
    public void consult(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询资讯换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=202"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("资讯换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 娱乐
     */
    @RequestMapping("/bili/recreation")
    @ResponseBody
    public void recreation(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询娱乐换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=5"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("娱乐换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 专栏
     */
    @RequestMapping("/bili/column")
    @ResponseBody
    public void column(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询专栏换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/article/recommends?ps=8"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("专栏换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());

    }

    /**
     * 电影
     */
    @RequestMapping("/bili/movie")
    @ResponseBody
    public void movie(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询电影换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=23"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("电影换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 电视剧
     */
    @RequestMapping("/bili/teleplay")
    @ResponseBody
    public void teleplay(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询电视剧换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=11"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("电视剧换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 影视
     */
    @RequestMapping("/bili/television")
    @ResponseBody
    public void television(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询影视换一换接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/dynamic/region?ps=12&rid=181"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("影视换一换接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 弹幕请求
     */
    @RequestMapping("/bili/bulletScreen")
    @ResponseBody
    public void bulletScreen(@RequestParam String callback, @RequestParam Integer aid, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询弹幕请求接口 => 请求参数：aid=" + aid);
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/v2/dm/ajax?aid=" + aid, String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("弹幕请求接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 合并图请求
     */
    @RequestMapping("/bili/mergeMap")
    @ResponseBody
    public void mergeMap(@RequestParam String callback, @RequestParam Integer aid, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询合并图请求接口 => 请求参数：aid=" + aid);
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pvideo?aid=" + aid, String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("合并图请求接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 搜索
     */
    @RequestMapping("/bili/search")
    @ResponseBody
    public void search(@RequestParam String callback, @RequestParam Double rnd, @RequestParam String term, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询搜索接口 => 请求参数：term=" + term + "，rnd=" + rnd);
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://s.search.bilibili.com/main/suggest?func=suggest&suggest_type=accurate&sub_type=tag&main_ver=v1&highlight=&userid=12980612&bangumi_acc_num=1&special_acc_num=1&topic_acc_num=1&upuser_acc_num=3&tag_num=10&special_num=10&bangumi_num=10&upuser_num=3&term=" + term + "&rnd=" + rnd, String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("搜索接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 搜索框提示词
     */
    @RequestMapping("/bili/keyword")
    @ResponseBody
    public void keyword(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询搜索框提示词接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/search/default"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("搜索框提示词接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 每一分区对应的排行榜 https://api.bilibili.com/x/web-interface/ranking/region?rid=对应分区的rid值&day=3&original=0
     */
    @RequestMapping("/bili/regionalRank")
    @ResponseBody
    public void regionalRank(@RequestParam String callback, HttpServletResponse response, @RequestParam Integer rid) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询每一分区对应的排行榜接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/ranking/region?rid=" + rid + "&day=3&original=0"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("每一分区对应的排行榜接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 特别推荐 https://www.bilibili.com/index/recommend.json
     */
    @RequestMapping("/bili/particularlyRecommend")
    @ResponseBody
    public void particularlyRecommend(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询特别推荐接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://www.bilibili.com/index/recommend.json"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("特别推荐查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 纪录片旁边的排行榜 https://api.bilibili.com/pgc/season/rank/web/list?season_type=3&day=3
     */
    @RequestMapping("/bili/documentaryRank")
    @ResponseBody
    public void documentaryRank(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询纪录片旁边的排行榜接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/season/rank/web/list?season_type=3&day=3"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("纪录片旁边的排行榜接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 正在直播旁边的 直播排行 关注的主播  为你推荐 https://api.live.bilibili.com/xlive/web-interface/v1/webMain/getList?platform=web
     */
    @RequestMapping("/bili/liveInfo")
    @ResponseBody
    public void liveInfo(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询正在直播旁边的直播排行,关注的主播,为你推荐接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.live.bilibili.com/xlive/web-interface/v1/webMain/getList?platform=web"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("正在直播旁边的直播排行,关注的主播,为你推荐接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 番剧旁边的轮播图 https://api.bilibili.com/pgc/operation/api/slideshow?position_id=104
     */
    @RequestMapping("/bili/bangumiCarousel")
    @ResponseBody
    public void bangumiCarousel(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询番剧旁边的轮播图接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/operation/api/slideshow?position_id=104"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("番剧旁边的轮播图查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 番剧加上排行榜一起的数据 https://api.bilibili.com/pgc/web/timeline/v2?season_type=1
     */
    @RequestMapping("/bili/bangumiRank")
    @ResponseBody
    public void bangumiRank(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询番剧加上排行榜一起的数据接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/web/timeline/v2?season_type=1"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("番剧加上排行榜一起的数据接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 国创右侧的排行榜 https://api.bilibili.com/pgc/season/rank/web/list?season_type=4&day=3
     */
    @RequestMapping("/bili/theGenRank")
    @ResponseBody
    public void theGenRank(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询国创右侧的排行榜接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/season/rank/web/list?season_type=4&day=3"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("国创右侧的排行榜接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 国创排行榜下面的轮播图 https://api.bilibili.com/pgc/operation/api/slideshow?position_id=101
     */
    @RequestMapping("/bili/theGenCarousel")
    @ResponseBody
    public void theGenCarousel(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询国创排行榜下面的轮播图接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/operation/api/slideshow?position_id=101"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("国创排行榜下面的轮播图接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 漫画右侧的排行榜  https://manga.bilibili.com/twirp/comic.v1.Comic/HomeFans
     */
    @RequestMapping("/bili/cartoonRank")
    @ResponseBody
    public void cartoonRank(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询漫画右侧的排行榜接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://manga.bilibili.com/twirp/comic.v1.Comic/HomeFans"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("漫画右侧的排行榜接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 电视剧旁边的排行榜 https://api.bilibili.com/pgc/season/rank/web/list?season_type=5&day=3
     */
    @RequestMapping("/bili/teleplayRank")
    @ResponseBody
    public void teleplayRank(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询电视剧旁边的排行榜接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/season/rank/web/list?season_type=5&day=3"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("电视剧旁边的排行榜接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 推荐视频： https://www.bilibili.com/index/ding.json
     */
    @RequestMapping("/bili/recommendVideo")
    @ResponseBody
    public void recommendVideo(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询推荐视频接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://www.bilibili.com/index/ding.json"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("推荐视频接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 我自己的个人信息：https://api.bilibili.com/x/web-interface/nav?build=0&mobi_app=web
     */
    @RequestMapping("/bili/personalInformation")
    @ResponseBody
    public void personalInformation(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询我自己的个人信息接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/web-interface/nav?build=0&mobi_app=web"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("我自己的个人信息接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 最顶部轮播图接口：https://api.bilibili.com/pgc/operation/api/slideshow?position_id=97
     */
    @RequestMapping("/bili/topCarousel")
    @ResponseBody
    public void topCarousel(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询最顶部轮播图接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/operation/api/slideshow?position_id=97"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("最顶部轮播图接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 热门直播接口：https://api.live.bilibili.com/xlive/web-interface/v1/index/RoomForWebMainHover
     */
    @RequestMapping("/bili/hotLive")
    @ResponseBody
    public void hotLive(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询热门直播接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.live.bilibili.com/xlive/web-interface/v1/index/RoomForWebMainHover"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("热门直播接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 专栏排行榜：https://api.bilibili.com/x/article/rank/list?cid=3
     */
    @RequestMapping("/bili/specialColumn")
    @ResponseBody
    public void specialColumn(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询专栏排行榜接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/x/article/rank/list?cid=3"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("专栏排行榜接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 电影排行榜：https://api.bilibili.com/pgc/season/rank/web/list?season_type=2&day=3
     */
    @RequestMapping("/bili/movieRank")
    @ResponseBody
    public void movieRank(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询电影排行榜接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/season/rank/web/list?season_type=2&day=3"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("电影排行榜接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 番剧排行榜：https://api.bilibili.com/pgc/web/rank/list?season_type=1&day=3
     */
    @RequestMapping("/bili/bangumiRanks")
    @ResponseBody
    public void bangumiRanks(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询番剧排行榜接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/web/rank/list?season_type=1&day=3"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("番剧排行榜接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    /**
     * 国创最新到周日：https://api.bilibili.com/pgc/web/timeline/v2?season_type=4
     */
    @RequestMapping("/bili/theGenNew")
    @ResponseBody
    public void theGenNew(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询国创最新到周日接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.bilibili.com/pgc/web/timeline/v2?season_type=4"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("国创最新到周日接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    @RequestMapping("/bili/artWater")
    @ResponseBody
    public void artWater(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询artWater接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.vc.bilibili.com/link_draw/v2/Doc/index?type=recommend&page_num=0&page_size=20"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("artWater接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }

    @RequestMapping("/bili/photoWater")
    @ResponseBody
    public void photoWater(@RequestParam String callback, HttpServletResponse response) {
        /*response.setHeader("Access-Control-Allow-Origin","*");*/
        logger.info("查询photoWater接口......");
        response.setCharacterEncoding("UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(restTemplate
                .getForObject("https://api.vc.bilibili.com/link_draw/v2/Photo/index?type=recommend&page_num=0&page_size=20"
                        , String.class));
        try {
            response.getWriter().print(callback + "(" + jsonObject + ")");
            response.flushBuffer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        logger.info("photoWater接口查询成功！返回参数 = >" + jsonObject.toJSONString());
    }



    /*@RequestMapping("/bili/live")
    @ResponseBody
    public String live(){
        String info = JSONObject.parseObject(restTemplate
                .getForObject("https://api.live.bilibili.com/xlive/web-interface/v1/webMain/getMoreRecList?platform=web"
                        , String.class)).toJSONString();
        return info;
    }

    @RequestMapping("/testAjaxJsonp")
    public void testAjaxJsonp(@RequestParam String callback,HttpServletResponse response){
        try {
            // 这里jsonp返回的数据是固定格式 文后有详细解释
            response.getWriter().print(callback+"({\"id\":1})");
            response.flushBuffer();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/

}
